package models;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import objects.Constituent;
import objects.FeaturesDatabase;

import org.xml.sax.SAXException;

/* Reads from and Writes to XML files */
public class FeaturesModel {
	
	/* static features variable to remove need for creating FeatureModel objects */
	private static ArrayList<Constituent> features;
	
	public FeaturesModel() {}
	
	public static void read() throws ParserConfigurationException, SAXException, IOException {
		FeatureXMLReader reader = new FeatureXMLReader();
		reader.read("src/xml/features/features.xml");
		features = reader.getDatabase();
	}
	
	public static void write() throws FileNotFoundException, IOException {
		FeaturesDatabase db = new FeaturesDatabase();
		db.setConstituents(features);
		
		FeatureXMLWriter writer = new FeatureXMLWriter();
		writer.setDatabase(db);
		writer.write("src/xml/features/features.xml");
	}
	
	/** Get/Set data **/
	
	public static void setFeatures(ArrayList<Constituent> newFeatures) {
		features = newFeatures;
	}
	
	public static ArrayList<Constituent> getFeatures() {
		return features;
	}
	
}
